<template>
  <el-dialog
  title="修改"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">

   <!-- 引入form表单 -->
<el-form :model="dialogForm" :rules="rules" ref="addForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="订单号" prop="ordernum">
        <el-input v-model="dialogForm.ordernum"></el-input>
    </el-form-item>
    <el-form-item label="价格" prop="money">
        <el-input v-model="dialogForm.money"></el-input>
    </el-form-item>
     <el-form-item>
    <el-form-item label="订单状态" props="type">
        <el-select v-model="dialogForm.type" placeholder="请选择订单状态">
            <el-option :value="0" label="待支付"></el-option>
            <el-option :value="1" label="已关闭"></el-option>
            <el-option :value="2" label="待确认"></el-option>
            <el-option :value="3" label="学习中"></el-option>
            <el-option :value="4" label="已完成"></el-option>
        </el-select>
    </el-form-item>
 </el-form-item>
</el-form>
  
  <span slot="footer" class="dialog-footer">
    <el-button @click="closeIsshow">取 消</el-button>
    <el-button type="primary" @click="submitForm('addForm')">提 交</el-button>
  </span>
</el-dialog>

</template>

<script>
import { dialogFinanceApi } from '../../../api/financeApi'
export default {
    props:['dialogRow'],
     
    data() {
      return {
        dialogVisible: true,//永久显示
         dialogForm: {
          id:'', //修改用
          ordernum:'',
          money:'',
          type:'',
        },
        rules: {
          ordernum: [
            { required: true, message: '请输入订单号', trigger: 'blur' },
          ],
          type: [
            {  required: true, message: '请选择订单状态', trigger: 'change' }
          ],
          money: [
            { required: true, message: '请输入价格', trigger: 'blur' }
          ]
        },

      }
    },
    mounted() {
      console.log('this.dialogRow',this.dialogRow);
        // this.dialogForm = this.dialogRow 错误的
      this.dialogForm = JSON.parse(JSON.stringify(this.dialogRow))//对象赋值,深拷贝
    },
   
    methods: {
        submitForm(addForm) {
          this.$refs[addForm].validate((valid) => {
          if (valid) {
            dialogFinanceApi(this.dialogForm).then(res=>{
                console.log('res',res);
                if(res.code===200){
                     // 关闭弹框
                this.$emit('parentClose')
                // 刷新表格
                this.$emit('parentChange')

                }
               
            })
            // alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        })
      },
        closeIsshow(){
            this.$emit('parentClose')
            // this.$parent.isShow = false
        },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
            this.$emit('parentClose')
          })
          .catch(_ => {});
      }
    }

}
</script>

<style>

</style>